﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace JTLeigh.Commerce.Spencer.Features.ProductFeedback.Business.UnitTests
{

	/// <summary>
	/// Unit tests for the <see cref="AttributeBooleanCounter"/> class.
	/// </summary>
	[TestClass]
	public class AttributeBooleanCounterFixture
	{

		#region Methods

		/// <summary>
		/// Tests all methods and properties of the counter.
		/// </summary>
		[TestMethod]
		public void TestAttributeBooleanCounterOperation()
		{
			AttributeBooleanCounter counter;
			Guid attribute1Id;
			Guid attribute2Id;
			Dictionary<Guid, int> counts;

			counter = new AttributeBooleanCounter();
			Assert.AreEqual(0, counter.TotalCounts.Count);
			Assert.AreEqual(0, counter.PositiveCounts.Count);

			attribute1Id = Guid.NewGuid();
			counter.AddValue(attribute1Id, true);
			counter.AddValue(attribute1Id, true);
			counter.AddValue(attribute1Id, true);
			counter.AddValue(attribute1Id, false);
			counter.AddValue(attribute1Id, false);
			counts = counter.TotalCounts;
			Assert.AreEqual(1, counts.Count); // 1 attribute so far
			Assert.IsTrue(counts.ContainsKey(attribute1Id));
			Assert.AreEqual(5, counts[attribute1Id]);
			counts = counter.PositiveCounts;
			Assert.AreEqual(1, counts.Count); // 1 attribute so far
			Assert.IsTrue(counts.ContainsKey(attribute1Id));
			Assert.AreEqual(3, counts[attribute1Id]);

			attribute2Id = Guid.NewGuid();
			counter.AddValue(attribute2Id, true);
			counter.AddValue(attribute2Id, true);
			counter.AddValue(attribute2Id, false);
			counter.AddValue(attribute2Id, false);
			counter.AddValue(attribute2Id, false);
			counts = counter.TotalCounts;
			Assert.AreEqual(2, counts.Count); // 2 attributes now
			Assert.IsTrue(counts.ContainsKey(attribute2Id));
			Assert.AreEqual(5, counts[attribute1Id]);
			counts = counter.PositiveCounts;
			Assert.AreEqual(2, counts.Count); // 2 attributes now
			Assert.IsTrue(counts.ContainsKey(attribute2Id));
			Assert.AreEqual(2, counts[attribute2Id]);

			counter.Reset();
			Assert.AreEqual(0, counter.TotalCounts.Count);
			Assert.AreEqual(0, counter.PositiveCounts.Count);
		}

		#endregion // Methods

	}

}
